<template>
  <el-dialog :title="operation.title"  v-if="operation.state" :visible.sync="operation.state" width="80%">
    <div class="app-container">
      <el-row :gutter="10">
        <el-col  :xs="24">
          <el-form :model="queryParams" ref="queryForm" v-show="showSearch" label-width="68px" class="form-flex">
            <el-row :gutter="20">
              <el-col :span="6" :xs="24">
                <el-form-item label="余额单号" prop="balanceOdd">
                  <el-input v-model="queryParams.balanceOdd" placeholder="请输入余额单号" clearable size="small"
                    @keyup.enter.native="handleQuery" />
                </el-form-item>
              </el-col>
              <!-- <el-col :span="6" :xs="24">
                <el-form-item label="收费项目" prop="chargeId">
                  <el-input v-model="queryParams.chargeId" placeholder="请输入收费项目" clearable size="small"
                    @keyup.enter.native="handleQuery" />
                </el-form-item>
              </el-col> -->
              <el-col :span="6" :xs="24">
                <el-form-item label="收款方式" prop="payeeType">
                  <el-select v-model="queryParams.payeeType" placeholder="请选择收款方式" clearable size="small">
                    <el-option v-for="dict in dict.collection_method" :key="dict.dictValue" :label="dict.dictLabel"
                      :value="dict.dictValue" />
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="6" :xs="24">
                <el-form-item>
                  <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
                  <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>

          <el-row :gutter="10" class="mb8">
            <!-- <el-col :span="1.5">
              <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
                v-hasPermi="['payfee:balanceRefill:add']">新增</el-button>
            </el-col>
            <el-col :span="1.5">
              <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate"
                v-hasPermi="['payfee:balanceRefill:edit']">修改</el-button>
            </el-col> -->
            <el-col :span="1.5">
              <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple"
                @click="handleDelete" v-hasPermi="['payfee:balanceRefill:remove']">删除</el-button>
            </el-col>
            <!-- <el-col :span="1.5">
              <el-button type="warning" plain icon="el-icon-download" size="mini" :loading="exportLoading"
                @click="handleExport" v-hasPermi="['payfee:balanceRefill:export']">导出</el-button>
            </el-col> -->
            <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
          </el-row>

          <el-table v-loading="loading" :data="balanceRefillList" @selection-change="handleSelectionChange">
            <el-table-column type="selection" width="55" align="center" />
            <el-table-column label="余额单号" align="center" prop="balanceOdd" />
            <el-table-column label="所属房间" align="center" prop="roomName" width="180">
              <template slot-scope="scope">
                {{`${scope.row.roomName}[${scope.row.customName}]`}}
              </template>
            </el-table-column>
            <el-table-column label="收费项目" align="center" prop="chargeName" />
            <el-table-column label="充值金额" align="center" prop="rechargeMoney" />
            <el-table-column label="减免金额" align="center" prop="derateMoney" />
            <el-table-column label="实收金额" align="center" prop="receiptsMoney" />
            <el-table-column label="收款方式" align="center" prop="payeeType">
              <template slot-scope="scope">
                {{ dict.label.collection_method [scope.row.payeeType] }}
              </template>
            </el-table-column>
            <el-table-column label="收款人" align="center" prop="payeePerson" />
            <el-table-column label="收款时间" align="center" prop="payeeTime" width="180">
              <template slot-scope="scope">
                <span>{{ parseTime(scope.row.payeeTime, '{y}-{m}-{d}') }}</span>
              </template>
            </el-table-column>
            <el-table-column label="状态" align="center" prop="status">
              <template slot-scope="scope">
                {{ dict.label.charge_status[scope.row.status] }}
              </template>
            </el-table-column>
            <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
              <template slot-scope="scope">
               <!-- <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
                  v-if="scope.row.status!='10002'" v-hasPermi="['payfee:balanceRefill:edit']">修改</el-button> -->
                <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
                  v-if="scope.row.status!='10002'" v-hasPermi="['payfee:balanceRefill:remove']">删除</el-button>
              </template>
            </el-table-column>
          </el-table>
        </el-col>
      </el-row>
      <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
        @pagination="getList" />

    </div>
  </el-dialog>
</template>

<script>
  import {
    listMixin
  } from "@/utils/mixins/listMixin";
  import {
    listBalanceRefill,
    delBalanceRefill,
    exportBalanceRefill,
    getBalanceRefill
  } from "@/api/payfee/balanceRefill";
  import {
    listRoomBalance
  } from "@/api/payfee/roomBalance"

  export default {
    name: "BalanceRefillHistory",
    components: {
    },
    mixins: [listMixin],
    dicts: ['collection_method', 'charge_status', ],
    data() {
      return {
        // 余额充值表格数据
        balanceRefillList: [],
        currentNode: {},
        operation: {
          title: '',
          state: false
        },
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          balanceOdd: null,
          communityId: null,
          roomId: null,
          customId: null,
          chargeId: null,
          rechargeMoney: null,
          derateMoney: null,
          payeeType: null,
          payeePerson: null,
          payeeTime: null,
          deptId: null,
          ancestors: null,
        },

      };
    },
    methods: {
      showHistoryPage(roomId,chargeId) {
        this.operation.state = true;
       this.queryParams.roomId=roomId;
       this.queryParams.chargeId=chargeId;
       this.getList();
      },
      /** 查询余额充值列表 */
      getList() {
        this.loading = true;
        console.log("queryParams",this.queryParams)
        listBalanceRefill(this.queryParams).then(response => {
          console.log("1111",response)
          this.balanceRefillList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id)
        this.single = selection.length !== 1
        this.multiple = !selection.length
      },

      /** 修改按钮操作 */
      handleUpdate(row) {
        const id = row.id || this.ids
        getBalanceRefill(id).then(res => {
          if (res.data.status == '10002') {
            this.msgError("已收全单子不可修改");
            return;
          } else {
            const option = {
              "type": "UPDATE",
              "id": id
            }
            this.$refs.formRef.show({
              currentNode: this.currentNode,
              type: 'UPDATE',
              id: id
            })
          }
        })
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const ids = row.id || this.ids;
        this.$confirm('是否确认删除余额充值编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delBalanceRefill(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(() => {});
      },
      /** 导出按钮操作 */
      handleExport() {
        const queryParams = this.queryParams;
        this.$confirm('是否确认导出所有余额充值数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          this.exportLoading = true;
          return exportBalanceRefill(queryParams);
        }).then(response => {
          this.download(response.msg);
          this.exportLoading = false;
        }).catch(() => {});
      }
    }
  };
</script>

<style>
</style>
